﻿<Window x:Class="Conmigo.Widgets.AddressBook"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:widgets="clr-namespace:Conmigo.Widgets"
    xmlns:std="clr-namespace:Standard"
    Title="Conmigo">
  <Window.Style>
    <Style TargetType="{x:Type Window}">
      <Setter Property="Background" Value="Navy"/>
      <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(std:WindowChrome.WindowChrome).IsGlassCapable}" Value="True">
          <Setter Property="Background" Value="Transparent"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Window.Style>
  <std:WindowChrome.WindowChrome>
    <std:WindowChrome
      RoundCorners="True"
      RoundCornersRadius="8"/>
  </std:WindowChrome.WindowChrome>
  <Window.Resources>
    <!-- Converters -->
    <widgets:ContactUserTileToImageConverter x:Key="userTileConverter"/>
    <widgets:MultiplierConverter x:Key="multiplyBy"/>

    <!-- DataTemplate for displaying Contacts in the listbox.
         This is intended to look similar to the tile view in Vista's Explorer -->
    <DataTemplate x:Key="ContactItemTemplate">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
          <RowDefinition Height="*"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Image Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Source="{Binding Converter={StaticResource userTileConverter}}"/>
        <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding Path=Names.Default.FormattedName}"/>
        <TextBlock Grid.Column="2" Grid.Row="1"  Text="{Binding Path=EmailAddresses.Default.Address}"/>
        <TextBlock Grid.Column="2" Grid.Row="2" Text="{Binding Path=PhoneNumbers[Business].Number}"/>
      </Grid>
    </DataTemplate>

    <!-- Bluebar menu item style -->
    <Style TargetType="{x:Type MenuItem}">
      <Setter Property="Foreground" Value="White"/>
      <Setter Property="Margin" Value="3"/>
    </Style>

    <Style TargetType="{x:Type Menu}">
      <Setter Property="Background">
        <Setter.Value>
          <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#4B90Df" Offset="0" />
            <GradientStop Color="#295591" Offset=".5" />
            <GradientStop Color="#183D76" Offset="0.51" />
            <GradientStop Color="#325F9E" Offset="1" />
          </LinearGradientBrush>
        </Setter.Value>
      </Setter>
    </Style>

    <Style TargetType="{x:Type Button}" x:Key="captionButtonStyle">
      <Setter Property="Visibility" Value="Visible"/>
      <Setter Property="std:WindowChrome.HitTestable" Value="True"/>
      <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=(std:WindowChrome.WindowChrome).IsGlassCapable}" Value="True">
          <Setter Property="Visibility" Value="Hidden"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Window.Resources>

  <DockPanel x:Name="_NavigationRoot" Margin="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=(std:WindowChrome.WindowChrome).ResizeBorder}">
    <!-- Split the chrome area into its own panel -->
    <Grid DockPanel.Dock="Top" x:Name="_Caption">

      <Grid.RowDefinitions>
        <RowDefinition Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=(std:WindowChrome.WindowChrome).CaptionHeight}"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>

      <Menu Grid.Row="1"/>
      <Image Grid.Row="0" Grid.RowSpan="2"
             Source="{Binding Path=MeContact, Converter={StaticResource userTileConverter}}"
             Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=(std:WindowChrome.WindowChrome).CaptionHeight, Converter={StaticResource multiplyBy}, ConverterParameter=2}"
             Stretch="Uniform" 
             VerticalAlignment="Top"/>
      <DockPanel Grid.Column="1">
        <Button DockPanel.Dock="Right" x:Name="_CloseButton" Click="_OnCaptionButton" Style="{StaticResource captionButtonStyle}">X</Button>
        <Button DockPanel.Dock="Right" x:Name="_MaximizeButton" Click="_OnCaptionButton" Style="{StaticResource captionButtonStyle}">+</Button>
        <Button DockPanel.Dock="Right" x:Name="_MinimizeButton" Click="_OnCaptionButton" Style="{StaticResource captionButtonStyle}">-</Button>

        <TextBlock Grid.Column="1"
                   HorizontalAlignment ="Center"
                   VerticalAlignment="Top"
                   FontFamily="Segoe UI"
                   FontSize="9pt"  
                   Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Title}">
          <TextBlock.Style>
            <Style>
              <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
                  <Setter Property="TextBlock.BitmapEffect" Value="{x:Null}"/>
                  <Setter Property="TextBlock.Foreground" Value="White"/>
                </DataTrigger>
              </Style.Triggers>
              <Setter Property="TextBlock.BitmapEffect">
                <Setter.Value>
                  <OuterGlowBitmapEffect GlowColor="White" GlowSize="7"/>
                </Setter.Value>
              </Setter>
            </Style>
          </TextBlock.Style>
        </TextBlock>
      </DockPanel>

      <DockPanel Grid.Row="1" Grid.Column="1">
        <DockPanel.Background>
          <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#4B90Df" Offset="0" />
            <GradientStop Color="#295591" Offset=".5" />
            <GradientStop Color="#183D76" Offset="0.51" />
            <GradientStop Color="#325F9E" Offset="1" />
          </LinearGradientBrush>
        </DockPanel.Background>
        <DockPanel DockPanel.Dock="Right">
          <TextBlock DockPanel.Dock="Left" Foreground="White" VerticalAlignment="Center" Margin="2">
          <Italic>
            Search:
          </Italic>
          </TextBlock>
          <TextBox DockPanel.Dock="Right" Width="150" TextChanged="_FilterWordwheel" x:Name="_wordwheel" Margin="2"/>
        </DockPanel>
        <Menu DockPanel.Dock="Left">
          <MenuItem Header="_New Contact" Name="_newContactButton" Click="_OnNewContact"/>
          <MenuItem Header="_Delete" Name="_deleteContactButton" Click="_OnDelete"/>
          <MenuItem Header="_Import">
            <MenuItem Foreground="Black" Header="Import from _vCard" Name="_importButton" Click="_OnImportVcf"/>
          </MenuItem>
          <MenuItem Header="E_xport">
            <MenuItem Foreground="Black" Header="Export to _vCard" Name="_exportButton" Click="_OnExportVcf"/>
          </MenuItem>
          <MenuItem Header="Toggle _Glass" Click="_ToggleGlass"/>
        </Menu>
      </DockPanel>
    </Grid>

    <!-- Contact list takes up the rest of the available space -->
    <ListBox x:Name="_contactPanel"
             MouseDoubleClick="_OpenContact"
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"
             ItemTemplate="{StaticResource ContactItemTemplate}">
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <widgets:AnimatingTilePanel IsItemsHost="True" ItemHeight="64" ItemWidth="256"/>
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
    </ListBox>
  </DockPanel>
</Window>
